package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_ZHUI_BU_OR_TIAO_ZHAN_FROM_CROSS,desc = "追捕/挑战，区别与自动匹配对手")
public class DouLuoDaLuZhuiBuOrTiaoZhanCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        DouLuoDaLuProto.DouLuoDaLuZhuiBuOrTiaoZhanCrossRespMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuZhuiBuOrTiaoZhanCrossRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();

        player.getModule(PreReduceModule.class).restorePreReduce(reqMsg.getConsume());

        if(ret != 0){
            //重置门客次数与玩家派遣次数
            player.getModule(DouLuoDaLuModule.class).restoreTimes(reqMsg.getPatronsId(), reqMsg.getType());
        }else {
            //扣除消耗
            if(reqMsg.getType() == 3){
                //追捕
                player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(reqMsg.getConsume()), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuCaptureConsume);

            }else {
                //挑战
                player.getModule(CurrencyModule.class).removeCurrency(PropertyHelper.parseStringToProperty(reqMsg.getConsume()), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuChallengeConsume);
            }
            //门客的珍兽鱼类绑定一下活动
            player.getModule(VehicleModule.class).bindPatrons(reqMsg.getPatronsId(), DouLuoDaLuMgr.getActivityInfo().getActivityId());
        }

        if(ret == 0) {
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_ZHUI_BU_OR_TIAO_ZHAN, DouLuoDaLuProto.DouLuoDaLuZhuiBuOrTiaoZhanRespMsg.newBuilder().setRet(ret).setBattleData(reqMsg.getBattleData()));
        }else {
            player.sendPacket(Protocol.U_DOU_LUO_DA_LU_ZHUI_BU_OR_TIAO_ZHAN, DouLuoDaLuProto.DouLuoDaLuZhuiBuOrTiaoZhanRespMsg.newBuilder().setRet(ret));
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
